#ifndef __MOUSEDRIVER_H__
#define __MOUSEDRIVER_H__
#include "libs/types.h"
#include "kernel/interrupt/interrupt.h"

#define KBSTATUS_IBF	0x02
#define KBSTATUS_OBF	0x01

#define KB_BUF_SIZE 100

#define KB_INIT_MODE 0x47
#define KBCMD_SENDTO_MOUSE	0xd4  //发送数据
#define KBCMD_EN_MOUSE_INTFACE	0xa8 //开启鼠标
#define KBCMD_READ_CMD 0x20
#define KBCMD_WRITE_CMD 0x60

#define MOUSE_ENABLE		0xf4 //设置鼠标允许发送数据



#define  wait_KB_write()	while(io_in8(PORT_KB_STATUS) & KBSTATUS_IBF)
#define  wait_KB_read()		while(io_in8(PORT_KB_STATUS) & KBSTATUS_OBF)

struct mouse_packet
{	
	unsigned char Byte0;	//7:Y overflow,6:X overflow,5:Y sign bit,4:X sign bit,3:Always,2:Middle Btn,1:Right Btn,0:Left Btn
	char Byte1;	//X movement
	char Byte2;	//Y movement
};


class MouseDriver :public interrupthandler
{
private:
    /* data */
    uint8_t* p_head;
    uint8_t* p_tail;
    uint8_t buf[KB_BUF_SIZE];
    static int mouse_count;
    mouse_packet mouse;
public:
    int count;
    virtual StackFrame* handleInterrupt(StackFrame* fs);
    MouseDriver(interruptmanager* interrupts);
    uint8_t getMouseCode();
    void analysisMouseCode();
    ~MouseDriver();
};





#endif